package fun.qu_an.minecraft.fabric.fzbbl.event;

import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.item.ItemPlacementContext;

public final class PlayerPlaceEvents {
	public static final Event<PlayerPlacing> PLACING = EventFactory.createArrayBacked(PlayerPlacing.class,
		listeners -> context -> {
			for (PlayerPlacing listener : listeners) {
				if (!listener.onPlayerPlacing(context)) {
					return false;
				}
			}
			return true;
		});

	public static final Event<PlayerPlaced> PLACED = EventFactory.createArrayBacked(PlayerPlaced.class,
		listeners -> context -> {
			for (PlayerPlaced listener : listeners) {
				listener.onPlayerPlaced(context);
			}
		});

	@FunctionalInterface
	public interface PlayerPlacing {
		@SuppressWarnings("BooleanMethodIsAlwaysInverted")
		boolean onPlayerPlacing(ItemPlacementContext context);
	}

	@FunctionalInterface
	public interface PlayerPlaced {
		void onPlayerPlaced(ItemPlacementContext context);
	}
}
